package com.wd.tech.base;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.wd.tech.contract.IContract;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 时间：2020/7/1
 * 作者：徐黎明
 * 类的作用：
 */
public abstract class BaseActivity <P extends BasePresenter>  extends AppCompatActivity implements IContract.IView {
    public P mPresenter;
    private Unbinder bind;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutId());
        bind = ButterKnife.bind(this);
        //添加沉浸式
        if (getSupportActionBar()!=null){
            getSupportActionBar().hide();
        }
        mPresenter=initPresenter();
        if (mPresenter != null) {
            mPresenter.attach(this);
        }
        initView();
        initData();
    }

    protected abstract void initData();

    protected abstract void initView();

    protected abstract P initPresenter();

    protected abstract int layoutId();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //解决内存泄漏
        if (mPresenter == null) {
            mPresenter.deatch();
        }
        //bind解绑
        if (bind == null) {
            bind.unbind();
        }
    }
}
